/* The file is saved in UTF-8 codepage.
 * Check: «Stereotype», Section mark-§, Copyright-©, Alpha-α, Beta-β, Smile-☺
 */
package cz.pecinovsky.english.lootp.záloha_do_budoucna;

import java.lang.reflect.InvocationTargetException;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import cz.pecinovsky.english.lootp.utility.IO;
import java.util.Date;



public final class CM_0
{
    private static final long TIME = System.currentTimeMillis();

    private static CM_0 singleton = new CM_0();

    private JFrame frame;

//    static {
//        msg ("singleton=" + singleton);
//    }

    public static CM_0 getCanvas()
    {
        msg ("- getCanvas() started - singleton=" + singleton);
        try {
            singleton.frame.setVisible(true);
        }
        catch (Exception e) {
            msg("getCanvas() crashed");
            e.printStackTrace(System.out);
        }
        return singleton;
    }


    private CM_0()
    {
        msg ("Constructor started");
//        configurationFromFile();
//        try {
            SwingUtilities
//                    .invokeAndWait
                    .invokeLater
                    (new Runnable()
            {
                @Override
                public void run() {
                    msg ("The method run() started");
                    prepareAppWindow();
                    msg ("Preparation finished");
                }
            });
//        }
//        catch (InterruptedException ex) {
//            throw new RuntimeException(
//                    "\nApplication window preparation interrupted", ex);
//        }
//        catch (InvocationTargetException ex) {
//            throw new RuntimeException(
//                    "\nApplication window preparation did not succeed", ex);
//        }
        msg ("Initialization finished");
            IO.pause(1000);
        msg ("Constructor finished");
   }


    @SuppressWarnings("serial")         //Because of annonymous class
    private void prepareAppWindow()
    {
        msg ("- prepareAppWindow started");
        frame  = new JFrame();          //Create the new application window
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//        //Add the ubiquitous "Hello World" label.
//        JLabel label = new JLabel("Hello World");
//        frame.getContentPane().add(label);

        //Display the window.
        frame.pack();
//        frame.setVisible(true);
        msg ("- JFrame created");
     }


    private static synchronized void msg(String text)
    {
        double time = (System.currentTimeMillis() - TIME) / 1000.0;
        System.out.printf("%8.3f - %s%n", time, text);
    }


    public static void test()
    {
        msg("Test started");
        CM_0 instance = CM_0.getCanvas();
        msg("Test finished");
        System.exit(0);
    }
    /** @param args Command line arguments - not used. */
    public static void main(String[] args)  {  test();  }
}
